﻿using FluentNHibernate.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YYSite.Domain.System;
using YYSite.Domain.System.IdentityUsers;
using YYSite.Domain.System.Positions;
using YYSite.Domain.System.Roles;

namespace YYSite.Repository.System.IdentityUsers
{

    public class IdentityUserMap : ClassMap<IdentityUser>
    {
        public IdentityUserMap()
        {
            this.Table("IdentityUser");
            this.Schema(SystemConstant.Schema);
            this.Id(c => c.Id);
            this.Map(c => c.NickName).Length(128).Not.Nullable();
            this.Map(c => c.UserName).Length(128).Not.Nullable().Unique();
            this.Map(c => c.PasswordHash).Length(128);
            this.Map(c => c.SecurityStamp).Length(128);
            this.Map(c => c.Birthday);
            this.Map(c => c.PhoneNumber).Length(128);
            this.Map(c => c.PhoneNumberConfirmed);
            this.Map(c => c.Email).Length(128);
            this.Map(c => c.EmailConfirmed);
            this.Map(c => c.TwoFactorEnabled);
            this.Map(c => c.LockoutEndDateUtc);
            this.Map(c => c.LockoutEnabled);
            this.Map(c => c.AccessFailedCount);
            this.Map(c => c.WeiXinOpenId).Length(128);
            this.Map(c => c.WeiXinUnionId).Length(128);
            this.Map(c => c.HeadImageURL).Length(256);
            this.Map(c => c.CreateTime).Default("GETDATE()");

            this.HasManyToMany<Role>(p => p.Roles).AsSet().LazyLoad().ParentKeyColumn("UserId").ChildKeyColumn("RoleId").Table("System.UserRole");
            this.HasManyToMany<Position>(p => p.Positions).AsSet().LazyLoad().ParentKeyColumn("UserId").ChildKeyColumn("PositionId").Table("System.UserPosition");
        }
    }
}
